<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport"
        content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
	<link rel="stylesheet" type="text/css" href="../../css/api.css" />
	<link rel="stylesheet" type="text/css" href="../../css/common.css" />
	<link rel="stylesheet" type="text/css" href="../../css/aui.css" />
  <link rel="stylesheet" type="text/css" href="../../css/aui-pull-refresh.css" />
  <title>学术</title>
  <style>
		html, body {width: 100%;min-height: 100%;background: #f0f0f0;}
    .h20 {height: 0.5rem;background: #f0f0f0;}

    .ltContent .aui-list-item-title {
      color: #333;
      line-height: 1.2rem;
      font-size: 0.8rem;
    }
    .ltContent {
      margin-bottom: 2rem;
    }
    .ltContent .aui-list-item-text {
      color: #999;
      font-size: 0.7rem;
    }
    .ltContent .aui-list {
      background: #f0f0f0;
      margin-bottom: 2rem;
    }
    .ltContent .aui-list .aui-list-item {
      background: #fff;
      margin: 0.5rem 0;
    }
    .lt_btn {
      position: fixed;
      left: 0;
      bottom: 0;
      width: 100%;
    }
    .lt_btn a {
      display: block;
      width: 100%;
      text-align: center;
      padding: 0.5rem 0;
      color: #fff;
      font-size: 0.8rem;
      background: #2997e4;
      font-weight: bold;
    }
    .itemIco {
      width: 100%;
      height: 4rem;
    }
    .ltContent {
      min-height: calc(100vh - 65px);
    }
	</style>
</head>
<body>
<section class="aui-refresh-content">
<div id="app" v-cloak>
  <div class="aui-content aui-margin-b-15 ltContent">
    <ul class="aui-list aui-media-list">
      <li class="aui-list-item" v-for="item in newsList" @click="openDetail('xc', '论坛详情', item.newsId)">
        <div class="aui-media-list-item-inner">
          <div class="aui-list-item-media" style="width:6.5rem;">
              <div v-if="item.pics" class="itemIco" :style="'background: url('+ item.pics +') center/cover no-repeat'"></div>
              <div v-else class="itemIco" style="background: url(../../image/banner2@3x.png) center/cover no-repeat"></div>
          </div>
          <div class="aui-list-item-inner">
            <div class="aui-list-item-text">
              <div class="aui-list-item-title">{{item.title}}</div>
            </div>
            <div class="aui-list-item-text">
              {{item.content}}
            </div>
            <div class="aui-list-item-text">
              {{item.commentCount}}条评论
            </div>
          </div>
        </div>
      </li>
    </ul>
  </div>
</div>
</section>
<div class="lt_btn">
  <a href="javascript:;" onclick="ft()">发帖</a>
</div>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/vue.min.js"></script>
<script type="text/javascript" src="../../script/utils.js"></script>
<script type="text/javascript" src="../../script/common.js"></script>
<script type="text/javascript" src="../../script/aui-scroll.js"></script>
<script src="../../script/aui-pull-refresh.js"></script>
<script>

apiready = function() {
  var app = new Vue({
    el: '#app',
    data: {
      newsList: [],
      page: 1,
      totalpage: 1
    },
    created: function() {
      var $_this = this;

      api.ajax({
        url: window.Url.getArticleList + '6/' + $_this.page,
        timeout: 300,
      }, function(ret, err) {
          if (ret) {
              // api.alert({ msg: JSON.stringify(ret) });
              if (ret.data != null) {
                $_this.totalpage = ret.data.totalpage
                $_this.newsList = ret.data.newsList
              }

          } else {
              api.alert({ msg: JSON.stringify(err) });
          }
      })
      var scroll = new auiScroll({
							listen:true, //是否监听滚动高度，开启后将实时返回滚动高度
							distance:40 //判断到达底部的距离，isToBottom为true
					},function(ret){
						 if (ret.isToBottom) {
							 $_this.page ++
							 if ($_this.page > $_this.totalpage) {
								 $_this.page = $_this.totalpage
								 return
							 }
							 api.ajax({
                 url: window.Url.getArticleList + '6/' + $_this.page,
								timeout: 300,
							}, function(ret, err) {
									if (ret) {
										 //  api.alert({ msg: JSON.stringify(ret) });
											$_this.newsList = $_this.newsList.concat(ret.data.newsList)

									} else {
											api.alert({ msg: JSON.stringify(err) });
									}
							})
						 }

					})

          var pullRefresh = new auiPullToRefresh({
              container: document.querySelector('.aui-refresh-content'),
              triggerDistance: 100
          },function(ret){
              if(ret.status=="success"){
                $_this.page = 1
                api.ajax({
                  url: window.Url.getArticleList + '6/' + $_this.page,
                  timeout: 300,
                }, function(ret, err) {
                    if (ret) {
                        // api.alert({ msg: JSON.stringify(ret) });
                        setTimeout(function() {
                          if (ret.data != null) {
                            $_this.totalpage = ret.data.totalpage
                            $_this.newsList = ret.data.newsList
                          }
                          pullRefresh.cancelLoading(); //刷新成功后调用此方法隐藏
                        },500)


                    } else {
                        api.alert({ msg: JSON.stringify(err) });
                    }
                })

              }
          })
    },
    methods: {
      openDetail:function (type, title, id) {
        api.openWin({
          name: 'index_detail_' + type,
          pageParam: {
            name: 'index_detail_' + type,
            title: title,
            id: id,
            detail_type: 'lt'
          },
          url: './index_detail_' + type + '.html',
          delay: 200,
          bounces: false
        });
      }

    }
  })
}

function ft() {
  api.openWin({
    name: 'index_sj_ft',
    pageParam: {
      name: 'index_sj_ft',
    },
    url: './index_sj_ft.html',
    delay: 200,
    bounces: false
  });
}

</script>
</body>
</html>
